<?php
namespace app\common\process;

class GetOptions extends Base {
    private $privateScene = 'private';
    protected $upk = 'id';
    protected $uid = 'uid';

    protected $validate = null;
    protected $enum = null;
    
    public function __construct($validate = null, $enum = null, $options = []) {
        parent::__construct();
        $validate = $validate ? $validate : $this->validate;
        if($validate) {
            if(is_string($validate)) {
                $validate = loadValidate($validate);
            }
            $this->validate = $validate;
        }
        $enum = $enum ? $enum : $this->enum;
        if($enum) {
            if(is_string($enum)) {
                $enum = loadEnum($enum);
            }
            $this->enum = $enum;
        }
        if(is_array($options)) {
            foreach ($options as $key => $value) {
                $this->$key = $value;
            }
        }
    }

    //获取内容列表
    public function getShowOptions($fun = null) {
        return $enum->get_show_options($fun); 
    }

    //获取私密列表
    public function getOptions($user, $fun = null) {
        $validate = $this->validate;
        $post = [];
        $post[$this->uid] = $user[$this->upk];
        if (!$validate->scene($this->privateScene)->check($post)) {
            $this->error($validate->getError());
        }
        return $this->enum->get_user_options($fun);
    }
}
